/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:57 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class Chucnang_TacvuDAL : SqlProvider<Chucnang_TacvuEntity>
    {
        static Chucnang_TacvuDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Chucnang_TacvuEntity entity = new Chucnang_TacvuEntity();
				entity.PK_iChucnang_TacvuID = Int64.Parse("0"+dr["PK_iChucnang_TacvuID"].ToString());
				entity.FK_iChucnangID = Int32.Parse("0"+dr["FK_iChucnangID"].ToString());
				entity.FK_iTacvuID = Int32.Parse("0"+dr["FK_iTacvuID"].ToString());
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static Chucnang_TacvuEntity GetOne(Int64 PK_iChucnang_TacvuID)
        {
            string cmdName = "spChucnang_Tacvu_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iChucnang_TacvuID", PK_iChucnang_TacvuID);
            Chucnang_TacvuEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Chucnang_TacvuEntity> GetAll()
        {
            string cmdName = "spChucnang_Tacvu_Get";
            return GetList(cmdName);
        }
        public static List<Chucnang_TacvuEntity> GetByFK_iChucnangID(Int32 FK_iChucnangID)
		{
			string cmdName = "spChucnang_Tacvu_GetByFK_FK_iChucnangID";
			SqlParameter p = new SqlParameter("@FK_iChucnangID",FK_iChucnangID);
			List<Chucnang_TacvuEntity> list = GetList(cmdName, p);
			return list;
		}public static List<Chucnang_TacvuEntity> GetByFK_iTacvuID(Int32 FK_iTacvuID)
		{
			string cmdName = "spChucnang_Tacvu_GetByFK_FK_iTacvuID";
			SqlParameter p = new SqlParameter("@FK_iTacvuID",FK_iTacvuID);
			List<Chucnang_TacvuEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(Chucnang_TacvuEntity entity)
        {
            string cmdName = "spChucnang_Tacvu_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(Chucnang_TacvuEntity entity)
        {
            string cmdName = "spChucnang_Tacvu_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iChucnang_TacvuID)
        {
            string cmdName = "spChucnang_Tacvu_Delete";
            SqlParameter p = new SqlParameter("@PK_iChucnang_TacvuID", PK_iChucnang_TacvuID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Chucnang_TacvuEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iChucnang_TacvuID", entity.PK_iChucnang_TacvuID);
			p[1] = new SqlParameter("@FK_iChucnangID", entity.FK_iChucnangID);
			p[2] = new SqlParameter("@FK_iTacvuID", entity.FK_iTacvuID);
			p[3] = new SqlParameter("@sGhichu", entity.sGhichu);
            return p;
        }
        #endregion
       
    }
}